package com.vtb.thread;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.vtb.base.VtbBaseReadThread;
import com.vtb.entity.DataCache;
import com.vtb.entity.RrOauth;
import com.vtb.entity.Var;
import com.vtb.servlet.WtbException;

public class RrTraverThread extends VtbBaseReadThread{
	private static final Log log = LogFactory.getLog(RrTraverThread.class);
	public RrTraverThread(BlockingQueue<RrOauth> traver_rrQueue){
		this.traver_rrQueue = traver_rrQueue;
	}
	public void run() {
		log.info(Thread.currentThread().getName()+"--已启动");
		HashMap<String,RrOauth> rrMap = DataCache.synCloneMap(RrOauth.class);
		Collection<RrOauth> rrCollection;
		while (rrMap != null) {
			log.debug(Thread.currentThread().getName()+"在工作！");
			rrCollection = rrMap.values();
			for (Iterator<RrOauth> iterator = rrCollection.iterator(); iterator.hasNext();) {
				rrOauth = iterator.next();
				try {
					if (rrOauth.getR2q().equals(Var.OPEN) || rrOauth.getR2s().equals(Var.OPEN)) {
						traver_rrQueue.put(rrOauth);
					}
				} catch (InterruptedException e) {
					log.error("放入RR读取队列失败：", e);
					throw new WtbException("放入RR读取队列失败", e);
				}
			}
			try {
				log.debug("人人遍历线程在休息！");
				Thread.sleep(1000*60);
			} catch (InterruptedException e) {
			}
			rrMap = DataCache.synCloneMap(RrOauth.class);
		}
	}

}
